home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_37143.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  41 lines

  1. -- card: 37143 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 6
  9. ----- text -----
  10. 4.2  Objects & Messages
  11.  
  12. -- part contents for background part 4
  13. ----- text -----
  14. Thus far we have not declared any variables whose type is a class.  Such variables are called OBJECTS.  In TC (but not in C++) it is illegal to declare an identifier which is itself an object.  Rather, we must declare an identifier which is a pointer to an object of the desired class.  Since this is understood for all TC objects, we will not bother to indicate in the identifier name that it is a pointer as we usually do (e.g.  float  *f_ptr).  In fact, we will refer to the pointer as though it were the object itself.
  15.  
  16.     Student  *jack;       /* note: 'struct' is not needed */
  17.  
  18. Recall that defining a pointer to a data type allocates space only for a machine address; it does not allocate space for the data type - in this case a Student object - itself.  In C++ the 'new' operator allocates space for the instance variables of an object and returns a pointer to this space.  TC uses the new() function for this purpose.
  19.  
  20.     jack = new(Student);    /* in C++ the parentheses are not required */
  21.  
  22. Unlike the case with variables having "automatic" storage class*, space allocated by the new() function (or in C++ the 'new' operator) is not deallocated upon completion
  23.  
  24.  
  25.  
  26.  
  27. -- part contents for background part 29
  28. ----- text -----
  29. 28174
  30.  
  31. -- part contents for background part 27
  32. ----- text -----
  33. Automatic storage
  34.  
  35. -- part contents for background part 20
  36. ----- text -----
  37. Automatic storage - p77
  38.  
  39. -- part contents for background part 7
  40. ----- text -----
  41. 114